package cn.school.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.school.common.annotation.Log;
import cn.school.common.core.controller.BaseController;
import cn.school.common.core.domain.AjaxResult;
import cn.school.common.enums.BusinessType;
import cn.school.system.domain.BiPaper;
import cn.school.system.service.IBiPaperService;
import cn.school.common.utils.poi.ExcelUtil;
import cn.school.common.core.page.TableDataInfo;

/**
 * 纸条信息Controller
 *
 * @author ruoyi
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/system/paper")
public class BiPaperController extends BaseController
{
    @Autowired
    private IBiPaperService biPaperService;

    /**
     * 查询纸条信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:paper:list')")
    @GetMapping("/list")
    public TableDataInfo list(BiPaper biPaper)
    {
        startPage();
        biPaper.setStatus(null);
        List<BiPaper> list = biPaperService.selectBiPaperList(biPaper);
        return getDataTable(list);
    }

    /**
     * 导出纸条信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:paper:export')")
    @Log(title = "纸条信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BiPaper biPaper)
    {
        List<BiPaper> list = biPaperService.selectBiPaperList(biPaper);
        ExcelUtil<BiPaper> util = new ExcelUtil<BiPaper>(BiPaper.class);
        util.exportExcel(response, list, "纸条信息数据");
    }

    /**
     * 获取纸条信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:paper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(biPaperService.selectBiPaperById(id));
    }

    /**
     * 新增纸条信息
     */
    @PreAuthorize("@ss.hasPermi('system:paper:add')")
    @Log(title = "纸条信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BiPaper biPaper)
    {
        return toAjax(biPaperService.insertBiPaper(biPaper));
    }

    /**
     * 修改纸条信息
     */
    @PreAuthorize("@ss.hasPermi('system:paper:edit')")
    @Log(title = "纸条信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BiPaper biPaper)
    {
        return toAjax(biPaperService.updateBiPaper(biPaper));
    }

    /**
     * 删除纸条信息
     */
    @PreAuthorize("@ss.hasPermi('system:paper:remove')")
    @Log(title = "纸条信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(biPaperService.deleteBiPaperByIds(ids));
    }
}
